USE [CivilRegistry]
GO

IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_BirthCertificate_AddedUser]') AND parent_object_id = OBJECT_ID(N'[dbo].[BirthCertificate]'))
ALTER TABLE [dbo].[BirthCertificate] DROP CONSTRAINT [FK_BirthCertificate_AddedUser]
GO

IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_BirthCertificate_ApprovedUser]') AND parent_object_id = OBJECT_ID(N'[dbo].[BirthCertificate]'))
ALTER TABLE [dbo].[BirthCertificate] DROP CONSTRAINT [FK_BirthCertificate_ApprovedUser]
GO

IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_BirthCertificate_BirthReport]') AND parent_object_id = OBJECT_ID(N'[dbo].[BirthCertificate]'))
ALTER TABLE [dbo].[BirthCertificate] DROP CONSTRAINT [FK_BirthCertificate_BirthReport]
GO

IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_BirthCertificate_ModifiedUser]') AND parent_object_id = OBJECT_ID(N'[dbo].[BirthCertificate]'))
ALTER TABLE [dbo].[BirthCertificate] DROP CONSTRAINT [FK_BirthCertificate_ModifiedUser]
GO

IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_BirthCertificate_Person]') AND parent_object_id = OBJECT_ID(N'[dbo].[BirthCertificate]'))
ALTER TABLE [dbo].[BirthCertificate] DROP CONSTRAINT [FK_BirthCertificate_Person]
GO

IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[DF_BirthCertificate_IsApproved]') AND type = 'D')
BEGIN
ALTER TABLE [dbo].[BirthCertificate] DROP CONSTRAINT [DF_BirthCertificate_IsApproved]
END

GO

IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_BirthReport_AddedUser]') AND parent_object_id = OBJECT_ID(N'[dbo].[BirthReport]'))
ALTER TABLE [dbo].[BirthReport] DROP CONSTRAINT [FK_BirthReport_AddedUser]
GO

IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_BirthReport_AssociatedParent]') AND parent_object_id = OBJECT_ID(N'[dbo].[BirthReport]'))
ALTER TABLE [dbo].[BirthReport] DROP CONSTRAINT [FK_BirthReport_AssociatedParent]
GO

IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_BirthReport_CivilHospital]') AND parent_object_id = OBJECT_ID(N'[dbo].[BirthReport]'))
ALTER TABLE [dbo].[BirthReport] DROP CONSTRAINT [FK_BirthReport_CivilHospital]
GO

IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_BirthReport_ModifiedUser]') AND parent_object_id = OBJECT_ID(N'[dbo].[BirthReport]'))
ALTER TABLE [dbo].[BirthReport] DROP CONSTRAINT [FK_BirthReport_ModifiedUser]
GO

IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_Buisness_AddedUser]') AND parent_object_id = OBJECT_ID(N'[dbo].[Buisness]'))
ALTER TABLE [dbo].[Buisness] DROP CONSTRAINT [FK_Buisness_AddedUser]
GO

IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_Buisness_ModifiedUser]') AND parent_object_id = OBJECT_ID(N'[dbo].[Buisness]'))
ALTER TABLE [dbo].[Buisness] DROP CONSTRAINT [FK_Buisness_ModifiedUser]
GO

IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_District_State]') AND parent_object_id = OBJECT_ID(N'[dbo].[District]'))
ALTER TABLE [dbo].[District] DROP CONSTRAINT [FK_District_State]
GO

IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_Family_Person]') AND parent_object_id = OBJECT_ID(N'[dbo].[Family]'))
ALTER TABLE [dbo].[Family] DROP CONSTRAINT [FK_Family_Person]
GO

IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_PermanentAddress_District]') AND parent_object_id = OBJECT_ID(N'[dbo].[PermanentAddress]'))
ALTER TABLE [dbo].[PermanentAddress] DROP CONSTRAINT [FK_PermanentAddress_District]
GO

IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_PermanentAddress_ModifiedUser]') AND parent_object_id = OBJECT_ID(N'[dbo].[PermanentAddress]'))
ALTER TABLE [dbo].[PermanentAddress] DROP CONSTRAINT [FK_PermanentAddress_ModifiedUser]
GO

IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_PresentAddress_District]') AND parent_object_id = OBJECT_ID(N'[dbo].[PresentAddress]'))
ALTER TABLE [dbo].[PresentAddress] DROP CONSTRAINT [FK_PresentAddress_District]
GO

IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_PresentAddress_ModifiedUser]') AND parent_object_id = OBJECT_ID(N'[dbo].[PresentAddress]'))
ALTER TABLE [dbo].[PresentAddress] DROP CONSTRAINT [FK_PresentAddress_ModifiedUser]
GO

IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_RationCard_AddedUser]') AND parent_object_id = OBJECT_ID(N'[dbo].[RationCard]'))
ALTER TABLE [dbo].[RationCard] DROP CONSTRAINT [FK_RationCard_AddedUser]
GO

IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_RationCard_ApprovedUser]') AND parent_object_id = OBJECT_ID(N'[dbo].[RationCard]'))
ALTER TABLE [dbo].[RationCard] DROP CONSTRAINT [FK_RationCard_ApprovedUser]
GO

IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_RationCard_Family]') AND parent_object_id = OBJECT_ID(N'[dbo].[RationCard]'))
ALTER TABLE [dbo].[RationCard] DROP CONSTRAINT [FK_RationCard_Family]
GO

IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_RationCard_ModifiedUser]') AND parent_object_id = OBJECT_ID(N'[dbo].[RationCard]'))
ALTER TABLE [dbo].[RationCard] DROP CONSTRAINT [FK_RationCard_ModifiedUser]
GO

IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[DF_RationCard_IsApproved]') AND type = 'D')
BEGIN
ALTER TABLE [dbo].[RationCard] DROP CONSTRAINT [DF_RationCard_IsApproved]
END

GO

IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_Unsubscription_UnsubscriptionType]') AND parent_object_id = OBJECT_ID(N'[dbo].[Unsubscription]'))
ALTER TABLE [dbo].[Unsubscription] DROP CONSTRAINT [FK_Unsubscription_UnsubscriptionType]
GO

IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_Unsubscription_User]') AND parent_object_id = OBJECT_ID(N'[dbo].[Unsubscription]'))
ALTER TABLE [dbo].[Unsubscription] DROP CONSTRAINT [FK_Unsubscription_User]
GO

IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_Person_Business]') AND parent_object_id = OBJECT_ID(N'[dbo].[User]'))
ALTER TABLE [dbo].[User] DROP CONSTRAINT [FK_Person_Business]
GO

IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_Person_Family]') AND parent_object_id = OBJECT_ID(N'[dbo].[User]'))
ALTER TABLE [dbo].[User] DROP CONSTRAINT [FK_Person_Family]
GO

IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_Person_Role]') AND parent_object_id = OBJECT_ID(N'[dbo].[User]'))
ALTER TABLE [dbo].[User] DROP CONSTRAINT [FK_Person_Role]
GO

IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_User_AddedUser]') AND parent_object_id = OBJECT_ID(N'[dbo].[User]'))
ALTER TABLE [dbo].[User] DROP CONSTRAINT [FK_User_AddedUser]
GO

IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_User_ModifiedUser]') AND parent_object_id = OBJECT_ID(N'[dbo].[User]'))
ALTER TABLE [dbo].[User] DROP CONSTRAINT [FK_User_ModifiedUser]
GO

IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_User_PermanentAddress]') AND parent_object_id = OBJECT_ID(N'[dbo].[User]'))
ALTER TABLE [dbo].[User] DROP CONSTRAINT [FK_User_PermanentAddress]
GO

IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_User_PresentAddress]') AND parent_object_id = OBJECT_ID(N'[dbo].[User]'))
ALTER TABLE [dbo].[User] DROP CONSTRAINT [FK_User_PresentAddress]
GO

IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_VoterCard_AddedUser]') AND parent_object_id = OBJECT_ID(N'[dbo].[VoterCard]'))
ALTER TABLE [dbo].[VoterCard] DROP CONSTRAINT [FK_VoterCard_AddedUser]
GO

IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_VoterCard_ModifiedUser]') AND parent_object_id = OBJECT_ID(N'[dbo].[VoterCard]'))
ALTER TABLE [dbo].[VoterCard] DROP CONSTRAINT [FK_VoterCard_ModifiedUser]
GO

IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_VoterCard_Person]') AND parent_object_id = OBJECT_ID(N'[dbo].[VoterCard]'))
ALTER TABLE [dbo].[VoterCard] DROP CONSTRAINT [FK_VoterCard_Person]
GO

IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_VoterCard_UserApprove]') AND parent_object_id = OBJECT_ID(N'[dbo].[VoterCard]'))
ALTER TABLE [dbo].[VoterCard] DROP CONSTRAINT [FK_VoterCard_UserApprove]
GO

IF  EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[DF_VoterCard_IsApproved]') AND type = 'D')
BEGIN
ALTER TABLE [dbo].[VoterCard] DROP CONSTRAINT [DF_VoterCard_IsApproved]
END

GO

IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_RationCardAlterRequest_ApplicableUser]') AND parent_object_id = OBJECT_ID(N'[dbo].[RationCardAlterRequest]'))
ALTER TABLE [dbo].[RationCardAlterRequest] DROP CONSTRAINT [FK_RationCardAlterRequest_ApplicableUser]
GO

IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_RationCardAlterRequest_RationCardAlterRequestType]') AND parent_object_id = OBJECT_ID(N'[dbo].[RationCardAlterRequest]'))
ALTER TABLE [dbo].[RationCardAlterRequest] DROP CONSTRAINT [FK_RationCardAlterRequest_RationCardAlterRequestType]
GO

IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_RationCardAlterRequest_RequestedUser]') AND parent_object_id = OBJECT_ID(N'[dbo].[RationCardAlterRequest]'))
ALTER TABLE [dbo].[RationCardAlterRequest] DROP CONSTRAINT [FK_RationCardAlterRequest_RequestedUser]
GO

USE [CivilRegistry]
GO

/****** Object:  Table [dbo].[BirthCertificate]    Script Date: 04/08/2012 19:26:52 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[BirthCertificate]') AND type in (N'U'))
DROP TABLE [dbo].[BirthCertificate]
GO

/****** Object:  Table [dbo].[BirthReport]    Script Date: 04/08/2012 19:26:52 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[BirthReport]') AND type in (N'U'))
DROP TABLE [dbo].[BirthReport]
GO

/****** Object:  Table [dbo].[Buisness]    Script Date: 04/08/2012 19:26:52 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Buisness]') AND type in (N'U'))
DROP TABLE [dbo].[Buisness]
GO

/****** Object:  Table [dbo].[District]    Script Date: 04/08/2012 19:26:52 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[District]') AND type in (N'U'))
DROP TABLE [dbo].[District]
GO

/****** Object:  Table [dbo].[ErrorLog]    Script Date: 04/08/2012 19:26:52 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[ErrorLog]') AND type in (N'U'))
DROP TABLE [dbo].[ErrorLog]
GO

/****** Object:  Table [dbo].[Family]    Script Date: 04/08/2012 19:26:52 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Family]') AND type in (N'U'))
DROP TABLE [dbo].[Family]
GO

/****** Object:  Table [dbo].[PermanentAddress]    Script Date: 04/08/2012 19:26:52 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[PermanentAddress]') AND type in (N'U'))
DROP TABLE [dbo].[PermanentAddress]
GO

/****** Object:  Table [dbo].[PresentAddress]    Script Date: 04/08/2012 19:26:52 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[PresentAddress]') AND type in (N'U'))
DROP TABLE [dbo].[PresentAddress]
GO

/****** Object:  Table [dbo].[RationCard]    Script Date: 04/08/2012 19:26:52 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[RationCard]') AND type in (N'U'))
DROP TABLE [dbo].[RationCard]
GO

/****** Object:  Table [dbo].[Roles]    Script Date: 04/08/2012 19:26:52 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Roles]') AND type in (N'U'))
DROP TABLE [dbo].[Roles]
GO

/****** Object:  Table [dbo].[State]    Script Date: 04/08/2012 19:26:52 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[State]') AND type in (N'U'))
DROP TABLE [dbo].[State]
GO

/****** Object:  Table [dbo].[Unsubscription]    Script Date: 04/08/2012 19:26:52 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Unsubscription]') AND type in (N'U'))
DROP TABLE [dbo].[Unsubscription]
GO

/****** Object:  Table [dbo].[UnsubscriptionType]    Script Date: 04/08/2012 19:26:52 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[UnsubscriptionType]') AND type in (N'U'))
DROP TABLE [dbo].[UnsubscriptionType]
GO

/****** Object:  Table [dbo].[User]    Script Date: 04/08/2012 19:26:52 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[User]') AND type in (N'U'))
DROP TABLE [dbo].[User]
GO

/****** Object:  Table [dbo].[VoterCard]    Script Date: 04/08/2012 19:26:52 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[VoterCard]') AND type in (N'U'))
DROP TABLE [dbo].[VoterCard]
GO

/****** Object:  Table [dbo].[RationCardAlterRequest]    Script Date: 04/08/2012 19:26:52 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[RationCardAlterRequest]') AND type in (N'U'))
DROP TABLE [dbo].[RationCardAlterRequest]
GO

/****** Object:  Table [dbo].[RationCardAlterRequestType]    Script Date: 04/08/2012 19:26:52 ******/
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[RationCardAlterRequestType]') AND type in (N'U'))
DROP TABLE [dbo].[RationCardAlterRequestType]
GO

USE [CivilRegistry]
GO

/****** Object:  Table [dbo].[BirthCertificate]    Script Date: 04/08/2012 19:26:52 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

SET ANSI_PADDING ON
GO

CREATE TABLE [dbo].[BirthCertificate](
	[BirthCertificateId] [int] IDENTITY(1,1) NOT NULL,
	[PersonId] [int] NOT NULL,
	[ChildFirshtName] [varchar](50) NOT NULL,
	[ChildMiddleName] [varchar](50) NOT NULL,
	[ChildLastName] [varchar](50) NULL,
	[BirthReportId] [int] NOT NULL,
	[IsApproved] [bit] NULL,
	[ApprovedUserId] [int] NULL,
	[AddedDate] [datetime] NOT NULL,
	[AddedUserId] [int] NOT NULL,
	[ModifiedDate] [datetime] NULL,
	[ModifiedUserId] [int] NULL,
	[DeactivateReason] [varchar](max) NULL,
	[DenayReason] [varchar](max) NULL,
 CONSTRAINT [PK_BirthCertificate] PRIMARY KEY CLUSTERED 
(
	[BirthCertificateId] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

SET ANSI_PADDING OFF
GO

USE [CivilRegistry]
GO

/****** Object:  Table [dbo].[BirthReport]    Script Date: 04/08/2012 19:26:52 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

SET ANSI_PADDING ON
GO

CREATE TABLE [dbo].[BirthReport](
	[BirthReportId] [int] IDENTITY(1,1) NOT NULL,
	[LocalGoanburah] [varchar](250) NULL,
	[CivilHospitalId] [int] NOT NULL,
	[LocalPHC] [varchar](250) NULL,
	[NursingHome] [varchar](250) NULL,
	[GenderOftheChild] [char](1) NULL,
	[AssociatedParentId] [int] NOT NULL,
	[DateOfBirthOftheChild] [datetime] NOT NULL,
	[VerificationCode] [varchar](250) NOT NULL,
	[IsApplied] [bit] NULL,
	[AddedDate] [datetime] NOT NULL,
	[AddedUserId] [int] NOT NULL,
	[ModifiedDate] [datetime] NULL,
	[ModifiedUserId] [int] NULL,
	[DeactivateReason] [varchar](max) NULL,
 CONSTRAINT [PK_BirthReport] PRIMARY KEY CLUSTERED 
(
	[BirthReportId] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

SET ANSI_PADDING OFF
GO

USE [CivilRegistry]
GO

/****** Object:  Table [dbo].[Buisness]    Script Date: 04/08/2012 19:26:52 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

SET ANSI_PADDING ON
GO

CREATE TABLE [dbo].[Buisness](
	[BuisnessId] [int] IDENTITY(1,1) NOT NULL,
	[IsGovt] [bit] NOT NULL,
	[Income] [int] NOT NULL,
	[Designation] [varchar](250) NOT NULL,
	[RegnoFirmCompany] [varchar](max) NOT NULL,
	[AddedDate] [datetime] NOT NULL,
	[AddedUserId] [int] NOT NULL,
	[ModifiedDate] [datetime] NULL,
	[ModifiedUserId] [int] NULL,
	[DeactivateReason] [varchar](max) NULL,
 CONSTRAINT [PK_Buisness] PRIMARY KEY CLUSTERED 
(
	[BuisnessId] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

SET ANSI_PADDING OFF
GO

USE [CivilRegistry]
GO

/****** Object:  Table [dbo].[District]    Script Date: 04/08/2012 19:26:52 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

SET ANSI_PADDING ON
GO

CREATE TABLE [dbo].[District](
	[DistrictId] [int] IDENTITY(1,1) NOT NULL,
	[DistrictName] [varchar](50) NOT NULL,
	[StateId] [int] NOT NULL,
 CONSTRAINT [PK_District] PRIMARY KEY CLUSTERED 
(
	[DistrictId] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

SET ANSI_PADDING OFF
GO

USE [CivilRegistry]
GO

/****** Object:  Table [dbo].[ErrorLog]    Script Date: 04/08/2012 19:26:52 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

SET ANSI_PADDING ON
GO

CREATE TABLE [dbo].[ErrorLog](
	[ErroroLogId] [int] IDENTITY(1,1) NOT NULL,
	[IsApplicationError] [bit] NOT NULL,
	[LineNumber] [int] NULL,
	[Page] [varchar](255) NULL,
	[ErrorMessage] [varchar](max) NULL,
	[StackTrace] [varchar](max) NULL,
	[ErrorDate] [datetime] NULL,
 CONSTRAINT [PK_ErrorLog] PRIMARY KEY CLUSTERED 
(
	[ErroroLogId] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

SET ANSI_PADDING OFF
GO

USE [CivilRegistry]
GO

/****** Object:  Table [dbo].[Family]    Script Date: 04/08/2012 19:26:52 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

SET ANSI_PADDING ON
GO

CREATE TABLE [dbo].[Family](
	[FamilyId] [int] IDENTITY(1,1) NOT NULL,
	[FamilyName] [varchar](250) NOT NULL,
	[OwnerId] [int] NOT NULL,
 CONSTRAINT [PK_Family] PRIMARY KEY CLUSTERED 
(
	[FamilyId] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

SET ANSI_PADDING OFF
GO

USE [CivilRegistry]
GO

/****** Object:  Table [dbo].[PermanentAddress]    Script Date: 04/08/2012 19:26:52 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

SET ANSI_PADDING ON
GO

CREATE TABLE [dbo].[PermanentAddress](
	[PermanentAddressId] [int] IDENTITY(1,1) NOT NULL,
	[Address] [varchar](max) NOT NULL,
	[PIN] [int] NOT NULL,
	[DistrictId] [int] NOT NULL,
	[City] [varchar](250) NOT NULL,
	[ModifiedDate] [datetime] NULL,
	[ModifiedUserId] [int] NULL,
 CONSTRAINT [PK_PermanentAddress] PRIMARY KEY CLUSTERED 
(
	[PermanentAddressId] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

SET ANSI_PADDING OFF
GO

USE [CivilRegistry]
GO

/****** Object:  Table [dbo].[PresentAddress]    Script Date: 04/08/2012 19:26:52 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

SET ANSI_PADDING ON
GO

CREATE TABLE [dbo].[PresentAddress](
	[PresentAddressId] [int] IDENTITY(1,1) NOT NULL,
	[Address] [varchar](max) NOT NULL,
	[PIN] [int] NOT NULL,
	[DistrictId] [int] NOT NULL,
	[City] [varchar](250) NOT NULL,
	[ModifiedDate] [datetime] NULL,
	[ModifiedUserId] [int] NULL,
 CONSTRAINT [PK_PresentAddress_1] PRIMARY KEY CLUSTERED 
(
	[PresentAddressId] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

SET ANSI_PADDING OFF
GO

USE [CivilRegistry]
GO

/****** Object:  Table [dbo].[RationCard]    Script Date: 04/08/2012 19:26:52 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

SET ANSI_PADDING ON
GO

CREATE TABLE [dbo].[RationCard](
	[RationCardId] [int] IDENTITY(1,1) NOT NULL,
	[RationCardFamilyId] [int] NOT NULL,
	[IsApproved] [bit] NULL,
	[ApprovedUserId] [int] NULL,
	[AddedDate] [datetime] NOT NULL,
	[AddedUserId] [int] NOT NULL,
	[ModifiedDate] [datetime] NULL,
	[ModifiedUserId] [int] NULL,
	[DeactivateReason] [varchar](max) NULL,
	[DenayReason] [varchar](max) NULL,
 CONSTRAINT [PK_RationCard] PRIMARY KEY CLUSTERED 
(
	[RationCardId] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

SET ANSI_PADDING OFF
GO

USE [CivilRegistry]
GO

/****** Object:  Table [dbo].[Roles]    Script Date: 04/08/2012 19:26:52 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

SET ANSI_PADDING ON
GO

CREATE TABLE [dbo].[Roles](
	[RoleId] [int] NOT NULL,
	[Role] [varchar](50) NULL,
 CONSTRAINT [PK_Roles] PRIMARY KEY CLUSTERED 
(
	[RoleId] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

SET ANSI_PADDING OFF
GO

USE [CivilRegistry]
GO

/****** Object:  Table [dbo].[State]    Script Date: 04/08/2012 19:26:52 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

SET ANSI_PADDING ON
GO

CREATE TABLE [dbo].[State](
	[StateId] [int] IDENTITY(1,1) NOT NULL,
	[StateName] [varchar](25) NOT NULL,
 CONSTRAINT [PK_PresentAddress] PRIMARY KEY CLUSTERED 
(
	[StateId] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

SET ANSI_PADDING OFF
GO

USE [CivilRegistry]
GO

/****** Object:  Table [dbo].[Unsubscription]    Script Date: 04/08/2012 19:26:52 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[Unsubscription](
	[UnsubscriptionId] [int] IDENTITY(1,1) NOT NULL,
	[UnsubscribedUserId] [int] NOT NULL,
	[UnsubscriptionTypeId] [int] NOT NULL,
 CONSTRAINT [PK_Unsubscription] PRIMARY KEY CLUSTERED 
(
	[UnsubscriptionId] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

USE [CivilRegistry]
GO

/****** Object:  Table [dbo].[UnsubscriptionType]    Script Date: 04/08/2012 19:26:52 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

SET ANSI_PADDING ON
GO

CREATE TABLE [dbo].[UnsubscriptionType](
	[UnsubscriptionTypeId] [int] IDENTITY(1,1) NOT NULL,
	[UnsubscriptionName] [varchar](50) NOT NULL,
 CONSTRAINT [PK_UnsubscriptionType] PRIMARY KEY CLUSTERED 
(
	[UnsubscriptionTypeId] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

SET ANSI_PADDING OFF
GO

USE [CivilRegistry]
GO

/****** Object:  Table [dbo].[User]    Script Date: 04/08/2012 19:26:52 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

SET ANSI_PADDING ON
GO

CREATE TABLE [dbo].[User](
	[UserId] [int] IDENTITY(1,1) NOT NULL,
	[RoleId] [int] NOT NULL,
	[UserName] [varchar](50) NOT NULL,
	[Password] [varchar](50) NOT NULL,
	[FirstName] [varchar](50) NOT NULL,
	[MiddleName] [varchar](50) NOT NULL,
	[LastName] [varchar](50) SPARSE  NULL,
	[MotherName] [varchar](50) NULL,
	[FatherName] [varchar](50) NULL,
	[GaurdianName] [varchar](50) NULL,
	[PermanentAddressId] [int] NOT NULL,
	[PresentAddressId] [int] SPARSE  NULL,
	[EmailAddress] [varchar](50) NOT NULL,
	[PhoneNo] [bigint] NOT NULL,
	[Gender] [char](1) NULL,
	[DateOfBirth] [datetime] NOT NULL,
	[FamilyId] [int] NULL,
	[BusinessDetailId] [int] NULL,
	[Status] [varchar](10) NULL,
	[IsFirstLogin] [bit] NULL,
	[AddedDate] [datetime] NOT NULL,
	[AddedUserId] [int] NOT NULL,
	[ModifiedDate] [datetime] NULL,
	[ModifiedUserId] [int] NULL,
	[DeactivateReason] [varchar](max) NULL,
 CONSTRAINT [PK_PersonDetails] PRIMARY KEY CLUSTERED 
(
	[UserId] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY],
 CONSTRAINT [IX_User] UNIQUE NONCLUSTERED 
(
	[UserName] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

SET ANSI_PADDING OFF
GO

USE [CivilRegistry]
GO

/****** Object:  Table [dbo].[VoterCard]    Script Date: 04/08/2012 19:26:52 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

SET ANSI_PADDING ON
GO

CREATE TABLE [dbo].[VoterCard](
	[VoterCardId] [int] IDENTITY(1,1) NOT NULL,
	[PersonId] [int] NOT NULL,
	[VoterId] [varchar](50) NOT NULL,
	[IsApproved] [bit] NULL,
	[ApprovedUserId] [int] NULL,
	[AddedDate] [datetime] NOT NULL,
	[AddedUserId] [int] NOT NULL,
	[ModifiedDate] [datetime] NULL,
	[ModifiedUserId] [int] NULL,
	[DeactivateReason] [varchar](max) NULL,
	[DenayReason] [varchar](max) NULL,
 CONSTRAINT [PK_VoterCard] PRIMARY KEY CLUSTERED 
(
	[VoterCardId] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

SET ANSI_PADDING OFF
GO

USE [CivilRegistry]
GO

/****** Object:  Table [dbo].[RationCardAlterRequest]    Script Date: 04/08/2012 19:26:52 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[RationCardAlterRequest](
	[RationCardAlterRequestId] [int] IDENTITY(1,1) NOT NULL,
	[RequestedUserId] [int] NOT NULL,
	[RequestTypeId] [int] NOT NULL,
	[ApplicableMemberId] [int] NOT NULL,
 CONSTRAINT [PK_RationCardAlterRequest] PRIMARY KEY CLUSTERED 
(
	[RationCardAlterRequestId] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

USE [CivilRegistry]
GO

/****** Object:  Table [dbo].[RationCardAlterRequestType]    Script Date: 04/08/2012 19:26:52 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

SET ANSI_PADDING ON
GO

CREATE TABLE [dbo].[RationCardAlterRequestType](
	[RationCardAlterRequestTypeId] [int] IDENTITY(1,1) NOT NULL,
	[RationCardAlterRequestTypeName] [varchar](50) NOT NULL,
 CONSTRAINT [PK_RationCardAlterRequestType] PRIMARY KEY CLUSTERED 
(
	[RationCardAlterRequestTypeId] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

SET ANSI_PADDING OFF
GO

ALTER TABLE [dbo].[BirthCertificate]  WITH CHECK ADD  CONSTRAINT [FK_BirthCertificate_AddedUser] FOREIGN KEY([AddedUserId])
REFERENCES [dbo].[User] ([UserId])
GO

ALTER TABLE [dbo].[BirthCertificate] CHECK CONSTRAINT [FK_BirthCertificate_AddedUser]
GO

ALTER TABLE [dbo].[BirthCertificate]  WITH CHECK ADD  CONSTRAINT [FK_BirthCertificate_ApprovedUser] FOREIGN KEY([ApprovedUserId])
REFERENCES [dbo].[User] ([UserId])
GO

ALTER TABLE [dbo].[BirthCertificate] CHECK CONSTRAINT [FK_BirthCertificate_ApprovedUser]
GO

ALTER TABLE [dbo].[BirthCertificate]  WITH CHECK ADD  CONSTRAINT [FK_BirthCertificate_BirthReport] FOREIGN KEY([BirthReportId])
REFERENCES [dbo].[BirthReport] ([BirthReportId])
GO

ALTER TABLE [dbo].[BirthCertificate] CHECK CONSTRAINT [FK_BirthCertificate_BirthReport]
GO

ALTER TABLE [dbo].[BirthCertificate]  WITH CHECK ADD  CONSTRAINT [FK_BirthCertificate_ModifiedUser] FOREIGN KEY([ModifiedUserId])
REFERENCES [dbo].[User] ([UserId])
GO

ALTER TABLE [dbo].[BirthCertificate] CHECK CONSTRAINT [FK_BirthCertificate_ModifiedUser]
GO

ALTER TABLE [dbo].[BirthCertificate]  WITH CHECK ADD  CONSTRAINT [FK_BirthCertificate_Person] FOREIGN KEY([PersonId])
REFERENCES [dbo].[User] ([UserId])
GO

ALTER TABLE [dbo].[BirthCertificate] CHECK CONSTRAINT [FK_BirthCertificate_Person]
GO

ALTER TABLE [dbo].[BirthCertificate] ADD  CONSTRAINT [DF_BirthCertificate_IsApproved]  DEFAULT ((0)) FOR [IsApproved]
GO

ALTER TABLE [dbo].[BirthReport]  WITH CHECK ADD  CONSTRAINT [FK_BirthReport_AddedUser] FOREIGN KEY([AddedUserId])
REFERENCES [dbo].[User] ([UserId])
GO

ALTER TABLE [dbo].[BirthReport] CHECK CONSTRAINT [FK_BirthReport_AddedUser]
GO

ALTER TABLE [dbo].[BirthReport]  WITH CHECK ADD  CONSTRAINT [FK_BirthReport_AssociatedParent] FOREIGN KEY([AssociatedParentId])
REFERENCES [dbo].[User] ([UserId])
GO

ALTER TABLE [dbo].[BirthReport] CHECK CONSTRAINT [FK_BirthReport_AssociatedParent]
GO

ALTER TABLE [dbo].[BirthReport]  WITH CHECK ADD  CONSTRAINT [FK_BirthReport_CivilHospital] FOREIGN KEY([CivilHospitalId])
REFERENCES [dbo].[User] ([UserId])
GO

ALTER TABLE [dbo].[BirthReport] CHECK CONSTRAINT [FK_BirthReport_CivilHospital]
GO

ALTER TABLE [dbo].[BirthReport]  WITH CHECK ADD  CONSTRAINT [FK_BirthReport_ModifiedUser] FOREIGN KEY([ModifiedUserId])
REFERENCES [dbo].[User] ([UserId])
GO

ALTER TABLE [dbo].[BirthReport] CHECK CONSTRAINT [FK_BirthReport_ModifiedUser]
GO

ALTER TABLE [dbo].[Buisness]  WITH CHECK ADD  CONSTRAINT [FK_Buisness_AddedUser] FOREIGN KEY([AddedUserId])
REFERENCES [dbo].[User] ([UserId])
GO

ALTER TABLE [dbo].[Buisness] CHECK CONSTRAINT [FK_Buisness_AddedUser]
GO

ALTER TABLE [dbo].[Buisness]  WITH CHECK ADD  CONSTRAINT [FK_Buisness_ModifiedUser] FOREIGN KEY([ModifiedUserId])
REFERENCES [dbo].[User] ([UserId])
GO

ALTER TABLE [dbo].[Buisness] CHECK CONSTRAINT [FK_Buisness_ModifiedUser]
GO

ALTER TABLE [dbo].[District]  WITH CHECK ADD  CONSTRAINT [FK_District_State] FOREIGN KEY([StateId])
REFERENCES [dbo].[State] ([StateId])
GO

ALTER TABLE [dbo].[District] CHECK CONSTRAINT [FK_District_State]
GO

ALTER TABLE [dbo].[Family]  WITH CHECK ADD  CONSTRAINT [FK_Family_Person] FOREIGN KEY([OwnerId])
REFERENCES [dbo].[User] ([UserId])
GO

ALTER TABLE [dbo].[Family] CHECK CONSTRAINT [FK_Family_Person]
GO

ALTER TABLE [dbo].[PermanentAddress]  WITH CHECK ADD  CONSTRAINT [FK_PermanentAddress_District] FOREIGN KEY([DistrictId])
REFERENCES [dbo].[District] ([DistrictId])
GO

ALTER TABLE [dbo].[PermanentAddress] CHECK CONSTRAINT [FK_PermanentAddress_District]
GO

ALTER TABLE [dbo].[PermanentAddress]  WITH CHECK ADD  CONSTRAINT [FK_PermanentAddress_ModifiedUser] FOREIGN KEY([ModifiedUserId])
REFERENCES [dbo].[User] ([UserId])
GO

ALTER TABLE [dbo].[PermanentAddress] CHECK CONSTRAINT [FK_PermanentAddress_ModifiedUser]
GO

ALTER TABLE [dbo].[PresentAddress]  WITH CHECK ADD  CONSTRAINT [FK_PresentAddress_District] FOREIGN KEY([DistrictId])
REFERENCES [dbo].[District] ([DistrictId])
GO

ALTER TABLE [dbo].[PresentAddress] CHECK CONSTRAINT [FK_PresentAddress_District]
GO

ALTER TABLE [dbo].[PresentAddress]  WITH CHECK ADD  CONSTRAINT [FK_PresentAddress_ModifiedUser] FOREIGN KEY([ModifiedUserId])
REFERENCES [dbo].[User] ([UserId])
GO

ALTER TABLE [dbo].[PresentAddress] CHECK CONSTRAINT [FK_PresentAddress_ModifiedUser]
GO

ALTER TABLE [dbo].[RationCard]  WITH CHECK ADD  CONSTRAINT [FK_RationCard_AddedUser] FOREIGN KEY([AddedUserId])
REFERENCES [dbo].[User] ([UserId])
GO

ALTER TABLE [dbo].[RationCard] CHECK CONSTRAINT [FK_RationCard_AddedUser]
GO

ALTER TABLE [dbo].[RationCard]  WITH CHECK ADD  CONSTRAINT [FK_RationCard_ApprovedUser] FOREIGN KEY([ApprovedUserId])
REFERENCES [dbo].[User] ([UserId])
GO

ALTER TABLE [dbo].[RationCard] CHECK CONSTRAINT [FK_RationCard_ApprovedUser]
GO

ALTER TABLE [dbo].[RationCard]  WITH CHECK ADD  CONSTRAINT [FK_RationCard_Family] FOREIGN KEY([RationCardFamilyId])
REFERENCES [dbo].[Family] ([FamilyId])
GO

ALTER TABLE [dbo].[RationCard] CHECK CONSTRAINT [FK_RationCard_Family]
GO

ALTER TABLE [dbo].[RationCard]  WITH CHECK ADD  CONSTRAINT [FK_RationCard_ModifiedUser] FOREIGN KEY([ModifiedUserId])
REFERENCES [dbo].[User] ([UserId])
GO

ALTER TABLE [dbo].[RationCard] CHECK CONSTRAINT [FK_RationCard_ModifiedUser]
GO

ALTER TABLE [dbo].[RationCard] ADD  CONSTRAINT [DF_RationCard_IsApproved]  DEFAULT ((0)) FOR [IsApproved]
GO

ALTER TABLE [dbo].[Unsubscription]  WITH CHECK ADD  CONSTRAINT [FK_Unsubscription_UnsubscriptionType] FOREIGN KEY([UnsubscriptionTypeId])
REFERENCES [dbo].[UnsubscriptionType] ([UnsubscriptionTypeId])
GO

ALTER TABLE [dbo].[Unsubscription] CHECK CONSTRAINT [FK_Unsubscription_UnsubscriptionType]
GO

ALTER TABLE [dbo].[Unsubscription]  WITH CHECK ADD  CONSTRAINT [FK_Unsubscription_User] FOREIGN KEY([UnsubscribedUserId])
REFERENCES [dbo].[User] ([UserId])
GO

ALTER TABLE [dbo].[Unsubscription] CHECK CONSTRAINT [FK_Unsubscription_User]
GO

ALTER TABLE [dbo].[User]  WITH CHECK ADD  CONSTRAINT [FK_Person_Business] FOREIGN KEY([BusinessDetailId])
REFERENCES [dbo].[Buisness] ([BuisnessId])
GO

ALTER TABLE [dbo].[User] CHECK CONSTRAINT [FK_Person_Business]
GO

ALTER TABLE [dbo].[User]  WITH CHECK ADD  CONSTRAINT [FK_Person_Family] FOREIGN KEY([FamilyId])
REFERENCES [dbo].[Family] ([FamilyId])
GO

ALTER TABLE [dbo].[User] CHECK CONSTRAINT [FK_Person_Family]
GO

ALTER TABLE [dbo].[User]  WITH CHECK ADD  CONSTRAINT [FK_Person_Role] FOREIGN KEY([RoleId])
REFERENCES [dbo].[Roles] ([RoleId])
GO

ALTER TABLE [dbo].[User] CHECK CONSTRAINT [FK_Person_Role]
GO

ALTER TABLE [dbo].[User]  WITH CHECK ADD  CONSTRAINT [FK_User_AddedUser] FOREIGN KEY([AddedUserId])
REFERENCES [dbo].[User] ([UserId])
GO

ALTER TABLE [dbo].[User] CHECK CONSTRAINT [FK_User_AddedUser]
GO

ALTER TABLE [dbo].[User]  WITH CHECK ADD  CONSTRAINT [FK_User_ModifiedUser] FOREIGN KEY([ModifiedUserId])
REFERENCES [dbo].[User] ([UserId])
GO

ALTER TABLE [dbo].[User] CHECK CONSTRAINT [FK_User_ModifiedUser]
GO

ALTER TABLE [dbo].[User]  WITH CHECK ADD  CONSTRAINT [FK_User_PermanentAddress] FOREIGN KEY([PermanentAddressId])
REFERENCES [dbo].[PermanentAddress] ([PermanentAddressId])
GO

ALTER TABLE [dbo].[User] CHECK CONSTRAINT [FK_User_PermanentAddress]
GO

ALTER TABLE [dbo].[User]  WITH CHECK ADD  CONSTRAINT [FK_User_PresentAddress] FOREIGN KEY([PresentAddressId])
REFERENCES [dbo].[PresentAddress] ([PresentAddressId])
GO

ALTER TABLE [dbo].[User] CHECK CONSTRAINT [FK_User_PresentAddress]
GO

ALTER TABLE [dbo].[VoterCard]  WITH CHECK ADD  CONSTRAINT [FK_VoterCard_AddedUser] FOREIGN KEY([AddedUserId])
REFERENCES [dbo].[User] ([UserId])
GO

ALTER TABLE [dbo].[VoterCard] CHECK CONSTRAINT [FK_VoterCard_AddedUser]
GO

ALTER TABLE [dbo].[VoterCard]  WITH CHECK ADD  CONSTRAINT [FK_VoterCard_ModifiedUser] FOREIGN KEY([ModifiedUserId])
REFERENCES [dbo].[User] ([UserId])
GO

ALTER TABLE [dbo].[VoterCard] CHECK CONSTRAINT [FK_VoterCard_ModifiedUser]
GO

ALTER TABLE [dbo].[VoterCard]  WITH CHECK ADD  CONSTRAINT [FK_VoterCard_Person] FOREIGN KEY([PersonId])
REFERENCES [dbo].[User] ([UserId])
GO

ALTER TABLE [dbo].[VoterCard] CHECK CONSTRAINT [FK_VoterCard_Person]
GO

ALTER TABLE [dbo].[VoterCard]  WITH CHECK ADD  CONSTRAINT [FK_VoterCard_UserApprove] FOREIGN KEY([ApprovedUserId])
REFERENCES [dbo].[User] ([UserId])
GO

ALTER TABLE [dbo].[VoterCard] CHECK CONSTRAINT [FK_VoterCard_UserApprove]
GO

ALTER TABLE [dbo].[VoterCard] ADD  CONSTRAINT [DF_VoterCard_IsApproved]  DEFAULT ((0)) FOR [IsApproved]
GO

ALTER TABLE [dbo].[RationCardAlterRequest]  WITH CHECK ADD  CONSTRAINT [FK_RationCardAlterRequest_ApplicableUser] FOREIGN KEY([ApplicableMemberId])
REFERENCES [dbo].[User] ([UserId])
GO

ALTER TABLE [dbo].[RationCardAlterRequest] CHECK CONSTRAINT [FK_RationCardAlterRequest_ApplicableUser]
GO

ALTER TABLE [dbo].[RationCardAlterRequest]  WITH CHECK ADD  CONSTRAINT [FK_RationCardAlterRequest_RationCardAlterRequestType] FOREIGN KEY([RequestTypeId])
REFERENCES [dbo].[RationCardAlterRequestType] ([RationCardAlterRequestTypeId])
GO

ALTER TABLE [dbo].[RationCardAlterRequest] CHECK CONSTRAINT [FK_RationCardAlterRequest_RationCardAlterRequestType]
GO

ALTER TABLE [dbo].[RationCardAlterRequest]  WITH CHECK ADD  CONSTRAINT [FK_RationCardAlterRequest_RequestedUser] FOREIGN KEY([RequestedUserId])
REFERENCES [dbo].[User] ([UserId])
GO

ALTER TABLE [dbo].[RationCardAlterRequest] CHECK CONSTRAINT [FK_RationCardAlterRequest_RequestedUser]
GO


